import 'dart:math';

import 'package:flutter/material.dart';

/// 旋转的图标，用于风扇开启的状态显示
class AnimationIcon extends StatefulWidget {
  final Widget child;
  const AnimationIcon({super.key, required this.child});

  @override
  State<AnimationIcon> createState() => _AnimationIcon();
}

class _AnimationIcon extends State<AnimationIcon> with SingleTickerProviderStateMixin {
  late AnimationController animationController;

  @override
  void dispose() {
    animationController.dispose();
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    animationController = AnimationController(
      vsync: this,
      duration: const Duration(seconds: 1, milliseconds: 800),
    );
    animationController.repeat();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
        animation: animationController,
        child: widget.child,
        builder: (_, widget) {
          return Transform.rotate(
            angle: animationController.value * pi * 2,
            child: widget,
          );
        }
    );
  }
}